package com.lagou.filter;

import com.lagou.utils.IpUtils;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

/**
 * @ClassName: TransportIPFilter
 * @Auther: Jerry
 * @Date: 2020/10/18 23:07
 * @Desctiption: TODO
 * @Version: 1.0
 */
@Activate(group = CommonConstants.CONSUMER)
public class TransportIPFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {

        // 获取服务端请求ip
        RpcContext.getContext().setAttachment("ip", IpUtils.getThreadLocalIp());

        return invoker.invoke(invocation);
    }

}
